package com.learn.order.message;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
public class MQMessageReceiver {

	// @RabbitListener(queues = "myqueue")
	// 自动创建队列
	// @RabbitListener(queuesToDeclare=@Queue("myqueue"))
	// 自动创建Exchange和Queue绑定
	@RabbitListener(bindings = @QueueBinding(exchange = @Exchange("order"), value = @Queue("order.myqueue")))
	public void receiver(String message) {
		log.info("接受到的消息:{}", message);
	}

	// 路由分组 服务分发product key一般定义为服务名
	@RabbitListener(bindings = @QueueBinding(exchange = @Exchange("order"), key = "product", value = @Queue("product.queue")))
	public void receiverProduct(String message) {
		log.info("Product接受到的消息:{}", message);
	}

	// 路由分组 服务分发pay key一般定义为服务名
	@RabbitListener(bindings = @QueueBinding(exchange = @Exchange("order"), key = "pay", value = @Queue("pay.queue")))
	public void receiverPay(String message) {
		log.info("Pay接受到的消息:{}", message);
	}
}
